<?php
/**
 * Created by PhpStorm.
 * User: joe
 * Date: 17-11-5
 * Time: 下午7:07
 */

namespace App\Controllers;

use \System\App;

class Index extends App
{
    public function __construct()
    {
        parent::__construct();
        $this->language->load('app/main');
    }

    public function index()
    {
        $total = $this->db->countAll('SystemEvents');
        $knob = [
            ['title' => "EMERGENCY"],
            ['title' => "ALERT"],
            ['title' => "CRITICAL"],
            ['title' => "ERROR"],
            ['title' => "WARNING"],
            ['title' => "NOTICE"],
            ['title' => "INFO"],
            ['title' => "DEBUG"],
        ];
        for ($i = 0; $i < 8; $i++) {
            $count = $this->db->table('SystemEvents')
                ->where('Priority', $i)
                ->get()
                ->count();
            $this->db->reset();
            $knob[$i]['count'] = round(($count / $total) * 50, 2);
        }

        $this->view->knob = $knob;

        $sql='SELECT DISTINCT `Facility` FROM `SystemEvents` ORDER BY Facility ASC';
        $this->view->hosts=$this->db->query($sql)->result();

        $this->render('front/home', 'front/header');
    }
}
